/**
 * 智慧云模块常量
 */

//系统环境基础变量
//var IMS_PATH = "/mcode";
var IMS_PATH = "/mclock";

var MAP_PATH = "C:\\Users\\Administrator\\Desktop\\test";

var DICT_PATH = "";
/**
 * 确认弹出框
 * @param info 提示信息
 * @param resultFunction 结果集方法
 */
function confirm(info,resultFunction) {
	swal({title: info,type: "warning",showCancelButton: true,confirmButtonColor: "#DD6B55",confirmButtonText: "是, 进行操作!",cancelButtonText: "不, 取消操作!",closeOnConfirm: false, closeOnCancel: false },resultFunction);
}
/**
 * 弹出框 loading
 * @param title
 * @param text
 */
function swalLoading(title,text){
	swal({
		title: title,   
		text: text,   
		type: "info",   
		showCancelButton: false, 
		showConfirmButton: false,
		closeOnConfirm: false,   
		showLoaderOnConfirm: true, 
	});
}

function confirmLoading(title, text, func){
	swal({   
		title: title,   
		text: text,   
		type: "info",   
		showCancelButton: true,   
		closeOnConfirm: false,   
		showLoaderOnConfirm: true, 
		confirmButtonText: "确定",
		cancelButtonText: "取消"
		},func);
}


/**
 * 取消操作提示框
 */
function cancel(){
	swal("取消", "您的操作已经取消 :)", "error");
}

/**
 * 异常操作提示框
 */
function error(msg){
	swal("", msg, "error");
}

/**
 * 成功操作提示框,自定义显示信息
 */
function succ(msg){
	swal("", msg, "success");
}

/**
 * 成功操作提示框
 */
function succ(){
	swal("", "您的操作成功！", "success");
}

/**
 * 校验框架
 * @param obj
 * @param rules
 * @param url
 * @param table
 * @param modal
 */
function validatezs(obj,rules,url,table,modal){
	DICT_PATH = url;
	obj.validate({
		  errorElement: 'span',
		  errorClass:'help-inline',
		  focusInvalid: false,
		  ignore: '',
		  rules: rules,
		  errorPlacement : function(error,element){error.insertAfter(element);},
		  highlight: function(element) {
			  $(element).closest('.control-group').removeClass('success');
			  $(element).closest('.help-inline').removeClass('valid');
			  $(element).closest('.help-inline').removeClass('ok');
			  $(element).closest('.control-group').addClass('error');
		  },
		  unhighlight: function(element) {$(element).closest('.control-group').removeClass('error');},
		  success: function(label) {
			  label.closest('.control-group').removeClass('error');
			  label.closest('.control-group').addClass('success');
			  label.closest('.help-inline').addClass('valid ok');
		  },
		  submitHandler:function(form) {
			  $.get(DICT_PATH, obj.serialize(), function(data){
				  if(data.flg) {
					  modal.modal("hide");
					  succ();
					  if(DICT_PATH.endsWith("updateDict")){
						  table.ajax.reload(null,false);
					  }else{
						  table.ajax.reload();
					  }
				  } else {modal.modal("hide");error("您的操作失败！");}
		  	}); return false;}
     });
}
/**
 * 时间格式化
 * @param fmt
 *  var time = new Date().Format("yyyy-MM-dd hh:mm:ss"); 
 * @returns
 * 
 */
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
/**
 * 计算当前时间的后几分钟时间
 * var date = "2016-09-27 11:59:46";
 * var temp = addMinutes(date,3);
 */
//计算后n分钟的时间
function addMinutes(date,minutes){
	minutes = parseInt(minutes);  
	var	interTimes=minutes*60*1000;
	interTimes = parseInt(interTimes);
	var longTime = new Date(date).getTime();
	return new Date(longTime+interTimes).Format("yyyy-MM-dd hh:mm:ss");
}

 
/**
 * 计算当前时间的前几分钟时间
 * var date = "2016-09-27 11:59:46";
 * var temp = desendMinutes(date,3);
 */

//计算前n分钟的时间
function desendMinutes(date,minutes){
	 minutes = parseInt(minutes);  
	 var interTimes=minutes*60*1000;
	 interTimes = parseInt(interTimes);  
	 return new Date(Date.parse(date)-interTimes).Format("yyyy-MM-dd hh:mm:ss");
 }

/*
 * 获取当前时间 
 * 例如：2016-11-24 8:45:20
 */
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var second = date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hours >= 0 && hours <= 9) {
    	hours = "0" + hours;
    }
    if (minutes >= 0 && minutes <= 9) {
    	minutes = "0" + minutes;
    }
    if (second >= 0 && second <= 9) {
    	second = "0" + second;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + hours + seperator2 + minutes
            + seperator2 + second;
    return currentdate;
}
/*
 * 获取当前时间凌晨：
 * 例如：2016-11-24 00:00:00
 */
function getTodayFormatdate(){
    var now = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var date = new Date(now.getTime() - 0.5 * 3600 * 1000);
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var second = date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hours >= 0 && hours <= 9) {
    	hours = "0" + hours;
    }
    if (minutes >= 0 && minutes <= 9) {
    	minutes = "0" + minutes;
    }
    if (second >= 0 && second <= 9) {
    	second = "0" + second;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + hours + seperator2 + minutes
            + seperator2 + second;
    return currentdate;

}

/**
 * 获取当前时间的前几天
 * @param days
 */
function getDateBeforeDays(days){
    var now = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var second = date.getSeconds();
    if(month<10){
    	month = "0"+month;
    }
    if(strDate<10){
    	strDate = "0"+strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;

}

/**
 * 获取当前时间前一周时间
 * 
 */

function getNowFormatDateBeforeWeek(){
    var now = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var date = new Date(now.getTime() - 7 * 24 * 3600 * 1000);
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var second = date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hours >= 0 && hours <= 9) {
    	hours = "0" + hours;
    }
    if (minutes >= 0 && minutes <= 9) {
    	minutes = "0" + minutes;
    }
    if (second >= 0 && second <= 9) {
    	second = "0" + second;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + hours + seperator2 + minutes
            + seperator2 + second;
    return currentdate;
}
/**
 * 
 * @param obj
 * @param url
 * @param aoColumns
 * @param aoColumnDefs
 * @param pagesize
 * @returns
 */

//dataTable表
function showDataTable(obj,url,aoColumns,aoColumnDefs,pagesize){
	if(pagesize == null) pagesize=8;
	return obj.DataTable({"bProcessing": true,"bLengthChange":true,"bProcessing":true,"bFilter": false,"bServerSide": true,
	        "bFilter": false,"bSort": false,"sAjaxSource": url,"pagingType":"full_numbers",
	        "fbServerData":function(sSource,aDataSet){$.ajax({"dataType":"json","type":"GET","url":sSource,"data":aDataSet});},
	        "aoColumns":aoColumns,"aoColumnDefs":aoColumnDefs,
	        "oLanguage":{"sUrl": IMS_PATH+"/resources/assets/plugins/dataTables/txt/page.txt"},
            "initComplete":function () {
                obj.prev().find('select').selectpicker('render');
                obj.prev().find('select').selectpicker('refresh');
                obj.prev().find('.btn-group').css('width','auto');
                obj.prev().find('.btn').css('background-color','#fff');
                obj.prev().find('.btn').css('border','#d8d8d8 solid 1px')
            }
	       });
}
